export function printString(str: string[]) {
  const index = p.index;
  return str.map(s => index + s);
}

export function flat(str: string[][]) {
  return str.reduce((acc, s) => acc.concat(s), [] as string[]);
}

export function suffix(str: string[], fix: string) {
  if (str.length === 0) return str;
  const last = str[str.length - 1];
  if (last.endsWith(fix)) {
    return str;
  } else {
    return [...str.slice(0, -1), last + fix];
  }
}

export function prefix(fix: string, str: string[]) {
  if (str.length === 0) return str;
  const first = str[0];
  if (first.startsWith(fix)) {
    return str;
  } else {
    return [fix + first, ...str.slice(1)];
  }
}

const p = Object.assign(printString, {
  index: '  ',
  flat: (str: string[][]) => printString(flat(str)),
  suffix: (str: string[], fix: string) => printString(suffix(str, fix)),
  prefix: (fix: string, str: string[]) => printString(prefix(fix, str)),
});

export default p;